package servlet;

import pojo.Brand; import service.BrandService; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException;
import java.util.List;

@WebServlet(name = "AddServlet",urlPatterns = "/add")
public class AddServlet extends HttpServlet {

     BrandService brandService=new BrandService();



    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//      1.  设置处理post请求乱码的字符集
        response.setContentType("text/html;charset=utf-8");
//        2.接收客户端提交的数据:brandName,companyName,ordered,description,status
        String brandName = request.getParameter("brandName");
        String companyName = request.getParameter("companyName");
        String ordered = request.getParameter("ordered");
        String description = request.getParameter("description");
        String status = request.getParameter("status");
//        3.将接收到的数据封装到 Brand 对象中
        Brand brand = new Brand();
        brand.setBrandName(brandName);
        brand.setBrandName(companyName);
        brand.setBrandName(ordered);
        brand.setBrandName(description);
        brand.setBrandName(status);
//        4.调用 BrandService 的 add() 方法进行添加的业务逻辑处理
        brandService.add(brand);
//        5.跳转到 selectAllServlet 重新查询数据(重定向)
        response.sendRedirect("selectAll");
    }
}
